﻿using System.Collections.Generic;
using WuDada.Trade.DataLoader.Domain;
using WuDada.Trade.DataLoader.Persistence;
using System;
using WuDada.Trade.DataLoader.Service;


namespace WuDada.Trade.DataLoader.Service.Impl
{
    public class DataLoadService : IDataLoadService
    {
        public IDataLoadDao DataLoadDao { get; set; }

        /// <summary>
        /// 新增股票歷史資料
        /// </summary>
        /// <param name="stockDataVO">被新增的股票歷史資料</param>
        /// <returns>新增後的股票歷史資料</returns>
        public StockDataVO CreateStockData(StockDataVO stockDataVO)
        {
            return DataLoadDao.CreateStockData(stockDataVO);   
        }

        /// <summary>
        /// 更新股票歷史資料
        /// </summary>
        /// <param name="stockDataVO">被更新的股票歷史資料</param>
        /// <returns>更新後的股票歷史資料</returns>
        public StockDataVO UpdateStockData(StockDataVO stockDataVO)
        {
            return DataLoadDao.UpdateStockData(stockDataVO);
        }

        /// <summary>
        /// 刪除股票歷史資料
        /// </summary>
        /// <param name="stockDataVO">被刪除的股票歷史資料</param>
        public void DeleteStockData(StockDataVO stockDataVO)
        {
            DataLoadDao.DeleteStockData(stockDataVO);
        }

        /// <summary>
        /// 取得股票歷史資料 By 識別碼
        /// </summary>
        /// <param name="stockDataId">識別碼</param>
        /// <returns>股票歷史資料</returns>
        public StockDataVO GetStockDataById(int stockDataId)
        {
            return DataLoadDao.GetStockDataById(stockDataId);
        }

        /// <summary>
        /// 取得股票歷史資料 By 股票代碼 And 資料日期/時間
        /// </summary>
        /// <param name="stockCode">股票代碼</param>
        /// <param name="dataTime">資料日期/時間</param>
        /// <returns>股票歷史資料</returns>
        public StockDataVO GetStockData(string stockCode, DateTime dataTime)
        {
            return DataLoadDao.GetStockData(stockCode, dataTime);
        }

        /// <summary>
        /// 取得股票歷史資料清單
        /// </summary>
        /// <param name="queryString">搜尋語法，用Where...order by ...</param>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <returns>股票歷史資料清單</returns>
        public IList<StockDataVO> GetStockDataList(string queryString, int pageIndex, int pageSize)
        {
            return DataLoadDao.GetStockDataList(queryString, pageIndex, pageSize);
        }

        /// <summary>
        /// 取得股票歷史資料清單
        /// </summary>
        /// <param name="queryString">搜尋語法，用Where...order by ...</param>
        /// <returns>股票歷史資料清單</returns>
        public IList<StockDataVO> GetStockDataList(string queryString)
        {
            return DataLoadDao.GetStockDataList(queryString);
        }

        /// <summary>
        /// 取得股票歷史資料清單
        /// </summary>
        /// <param name="stockCode">股票代碼</param>
        /// <param name="period">資料週期類型</param>
        /// <param name="startDate">起始時間</param>
        /// <param name="endDate">結束時間</param>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <param name="sortField">排序欄位</param>
        /// <param name="sortDesc">升降冪排序</param>
        /// <returns>股票歷史資料清單</returns>
        public IList<StockDataVO> GetStockDataList(string stockCode, StockDataVO.StockDataPeriod period, DateTime? startDate, DateTime? endDate, int pageIndex, int pageSize, string sortField, bool sortDesc)
        {
            return DataLoadDao.GetStockDataList(stockCode, period, startDate, endDate, pageIndex, pageSize, sortField, sortDesc);
        }

        /// <summary>
        /// 取得股票歷史資料清單
        /// </summary>
        /// <param name="stockCode">股票代碼</param>
        /// <param name="period">資料週期類型</param>
        /// <param name="startDate">起始時間</param>
        /// <param name="endDate">結束時間</param>
        /// <param name="sortField">排序欄位</param>
        /// <param name="sortDesc">升降冪排序</param>
        /// <returns>股票歷史資料清單</returns>
        public IList<StockDataVO> GetStockDataList(string stockCode, StockDataVO.StockDataPeriod period, DateTime? startDate, DateTime? endDate, string sortField, bool sortDesc)
        {
            return DataLoadDao.GetStockDataList(stockCode, period, startDate, endDate, sortField, sortDesc);
        }

        /// <summary>
        /// 取得股票歷史資料筆數
        /// </summary>
        /// <param name="stockCode">股票代碼</param>
        /// <param name="period">資料週期類型</param>
        /// <param name="startDate">起始時間</param>
        /// <param name="endDate">結束時間</param>
        /// <returns>股票歷史資料筆數</returns>
        public int CountStockData(string stockCode, StockDataVO.StockDataPeriod period, DateTime? startDate, DateTime? endDate)
        {
            return DataLoadDao.CountStockData(stockCode, period, startDate, endDate);
        }
    }
}
